package marchenko.springdao.repository.book;

import java.sql.ResultSet;
import java.sql.SQLException;

import marchenko.springdao.domain.Author;
import marchenko.springdao.domain.Book;
import marchenko.springdao.domain.BookClass;
import marchenko.springdao.domain.Genre;

import org.springframework.jdbc.core.RowMapper;

class BookMapper implements RowMapper<Book> {
	
	public Book mapRow(ResultSet resultSet, int i) throws SQLException {
		Book book = new Book();
		book.setBookId(resultSet.getInt("id"));
		
		BookClass bclass = new BookClass();
		bclass.setClassId(resultSet.getInt("class_id"));
		bclass.setClassName(resultSet.getString("class_name"));
		
		Author author = new Author();
		author.setAuthorId(resultSet.getInt("author_id"));
		author.setAuthorName(resultSet.getString("author_name"));
		bclass.setAuthor(author);
		
		Genre genre = new Genre();
		genre.setGenreId(resultSet.getInt("genre_id"));
		genre.setGenreName(resultSet.getString("genre_name"));
		bclass.setGenre(genre);
		
		bclass.setDescription(resultSet.getString("description"));
		book.setBclass(bclass);
		return book;
	}
}